//
//  ProgressPlay.m
//  IOSUI思路
//
//  Created by 崔博 on 2018/9/28.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "ProgressPlay.h"

@implementation ProgressPlay

- (void) play
{
    if (_timer) return ;
    _timer = [NSTimer scheduledTimerWithTimeInterval:PERIOD target:self selector:@selector(timeDidFire:) userInfo:nil repeats:YES];
}
- (void)pause
{
    [_timer invalidate];
    _timer = nil;
}
- (void) timeDidFire:(NSTimer *)timer
{
    // 判断进度是否大于等于 1.0
    if (self.postion >= 1.0) {
        self.postion = 0.0;
        [_timer invalidate];
        [self.delegate playDidStip:self];
    }
    else
    {
        self.postion += PERIOD / DURATION;
        [self.delegate player:self didReachPosition:self.postion];
    }
}
@end
